package com.nf.teamwork.mall.config.security.api;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.nf.teamwork.mall.vo.ResponseVO;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: LJP
 * @Classname JwtLoginSuccessHandler
 * @Date: 2020-03-01 19:15
 * @Description: 认证成功处理类
 */
public class JwtLoginSuccessHandler implements AuthenticationSuccessHandler {
    @Override
    public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
        httpServletResponse.setContentType("application/json;charset=UTF-8");
        ResponseVO vo = new ResponseVO();
        vo.setCode(httpServletResponse.SC_OK);
        vo.setMessage("login success");
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.writeValue(httpServletResponse.getOutputStream(), vo);
    }
}
